/* 811. 子域名访问计数 */
/**
 * @param {string[]} cpdomains
 * @return {string[]}
 */
/* 哈希表 */
var subdomainVisits = function (cpdomains) {
	const ans = []
	const map = new Map()
	for (const cpdomain of cpdomains) {
		const [count, domainName] = cpdomain.split(' ')
		let i = domainName.length - 1
		while (i--) {
			if (domainName[i - 1] === '.' || i === 0) {
				const key = domainName.slice(i)
				map.set(key, (map.get(key) || 0) + parseInt(count))
			}
		}
	}
	for (const [key, value] of map) {
		ans.push(`${value} ${key}`)
	}
	return ans
}
const res = subdomainVisits([
	'900 google.mail.com',
	'50 yahoo.com',
	'1 intel.mail.com',
	'5 wiki.org',
])
console.log('subdomainVisits :>>', res)
